package service

import (
	amount_v1 "amount1/api/Amount1Server/v1"
	"amount1/internal/biz"
	"context"
	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/trace"
)

type Amount1Service struct {
	amount_v1.UnimplementedAmount1ServiceServer

	bz *biz.Amount1BizStruct
}

func NewAmount1Service(bz *biz.Amount1BizStruct) *Amount1Service {
	return &Amount1Service{
		bz: bz,
	}
}

func (a *Amount1Service) TransOutOrder(ctx context.Context, req *amount_v1.TransOutOrderRequest) (*amount_v1.Empty, error) {
	ctx, span := otel.Tracer("Service").Start(ctx, "TransOutOrderService", trace.WithSpanKind(trace.SpanKindProducer))
	defer span.End()

	return a.bz.TransOutOrder(ctx, req)
}

func (a *Amount1Service) TransOutOrderCompensate(ctx context.Context, req *amount_v1.TransOutOrderCompensateRequest) (*amount_v1.Empty, error) {
	ctx, span := otel.Tracer("Service").Start(ctx, "TransOutOrderCompensateService", trace.WithSpanKind(trace.SpanKindProducer))
	defer span.End()
	return a.bz.TransOutOrderCompensate(ctx, req)
}

func (a *Amount1Service) DelRedisKeyDemo(ctx context.Context, req *amount_v1.Empty) (*amount_v1.Empty, error) {
	return a.bz.DelRedisKeyDemo(ctx, req)
}

func (a *Amount1Service) TestHttpRequest(ctx context.Context, req *amount_v1.HttpReq) (*amount_v1.Empty, error) {
	ctx, span := otel.Tracer("Service").Start(ctx, "TestHttpRequestService", trace.WithSpanKind(trace.SpanKindProducer))
	defer span.End()

	return a.bz.TestHttpRequest(ctx, req)
}

func (a *Amount1Service) TestAsyncRequestCtxWithoutCancel(ctx context.Context, req *amount_v1.HttpReq) (*amount_v1.Empty, error) {
	ctx, span := otel.Tracer("Service").Start(ctx, "TestAsyncRequestCtxWithoutCancelService", trace.WithSpanKind(trace.SpanKindProducer))
	defer span.End()

	return a.bz.TestAsyncRequestCtxWithoutCancel(ctx, req)
}
